<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="pojo.User" %>
<%@ page import="pojo.Device" %>
<%@ page import="tools.Translator" %>
<%@ page import="pojo.EUserType" %>
<%@ page import="utils.db.impl.DeviceFetcher" %>
<%@ page import="utils.db.impl.UserFetcher" %>
<%@ page import="java.util.List" %>
<script type="text/javascript" src="js/deviceChoice.js"></script>

<%
User user=(User)session.getAttribute("user");

%>
<%if (session.getAttribute("user") == null) {%>
<h1>Brak dostępu do tej strony!</h1>
<%}else{ 
	DeviceFetcher d=new DeviceFetcher();
	List<Device> devices = d.getDevices();
%>
<h1>Urządzenia</h1>
<div id="gallery_container">

<h3>Edytuj Dane:</h3>
<form action="EditDeviceServlet" method="POST">
<table>
		<tr>
		<td><label class="panel" for="login">Urządzenie: </label></td>
		<td>
		<div class="styled-select">
				<select name="deviceId" id="deviceId">
				<option value="0">Wybierz urządzenie... </option>
				<%
				
				for(int i=0;i<devices.size();i++){
					UserFetcher u = new UserFetcher();
					User client= u.getUserById(devices.get(i).getClientId());
					String clientName = client.getFirstName();
					String clientSurname = client.getLastName();
				%>
				<option value="<%=devices.get(i).getId()%>"><%=Translator.toPolish(String.valueOf(devices.get(i).getType()))%> - <%=clientName%> <%=clientSurname%></option>
				<%} %>
				</select>
				</div>
		</td>
		</tr>
		
		<tr>
		<td><label class="panel" for="login">Klient: </label></td> 
		<td><div class="styled-select">
				<select name="clientId" id="clientId">
				<option value="0">Wybierz klienta... </option>
				<%
				UserFetcher u = new UserFetcher();
				List<User> clients= u.getUsers(EUserType.CLIENT);
			
				for(int i=0;i<clients.size();i++){
					String clientName = clients.get(i).getFirstName();
					String clientSurname = clients.get(i).getLastName();
					int clientId = clients.get(i).getId();
				%>
				<option value="<%=clientId%>"><%=clientName%> <%=clientSurname%></option>
				<%} %>
				</select>
				</div></td> 
		</tr>
		
		<tr>
		<td><label class="panel" for="login">Serwisant: </label></td> 
		<td><div class="styled-select">
				<select name="servicemanId" id="servicemanId">
				<option value="0">Wybierz serwisanta... </option>
				<%
				List<User> servicemans = u.getUsers(EUserType.SERVICEMAN, EUserType.ADMIN);
				for(int i=0;i<servicemans.size();i++){
					
					
					String servicemanName = servicemans.get(i).getFirstName();
					String servicemanSurname = servicemans.get(i).getLastName();
					int servicemanId = servicemans.get(i).getId();
				%>
				<option value="<%=servicemanId%>"><%=servicemanName%> <%=servicemanSurname%></option>
				<%} %>
				</select>
				</div></td> 
		</tr>
		
		<tr>
		<td><label class="panel" for="login">Typ: </label></td> 
		<td>
			<div class="styled-select">
				<select name="type" id="type">
				<option value="0">Wybierz typ... </option>
				<option value="PC">PC </option>
				<option value="LAPTOP">LAPTOP </option>
				<option value="MONITOR">MONITOR </option>
				<option value="PRINTER">DRUKARKA </option>
				<option value="OTHER">INNE </option>
				</select>
			</div>
		</td> 
		</tr>
		
		<tr>
		<td><label class="panel" for="login">Opis: </label> 
		<td><textarea rows="10" cols="50" name="desc" id="desc">Opis urządzenia...</textarea></td> 
		</tr>
		
	
		
		</table> 
		
		<br>
		<center><input type="submit" class="styled-button-2" value="Zatwierdź"/></center>
		<br>
		<%if (session.getAttribute("editDevice") != null) {
	%>
	<span><%= session.getAttribute("editDevice") %></span> 
	<%
		session.removeAttribute("editDevice");
		}
	%>
	

</form>

<br><br>



<h3>Usuń urządzenie</h3>

<form action="DeleteDeviceServlet" method="POST"> 

<table>
<tr>
<td>
<div class="styled-select">
				<select name="delete" id="delete">
				<option value="0">Wybierz użytkownika do usunięcia... </option>
				<%
				
				for(int i=0;i<devices.size();i++){
					System.err.println(devices.get(i));
				%>
				<option value="<%=devices.get(i).getId()%>"><%=devices.get(i).getType()%> <%=devices.get(i).getDescription()%> - <%=devices.get(i).getClientId()%></option>
				<%} %>	
			</select></div></td>
			
			<td>
				<input type="submit" id="submit" class="styled-button-3" value="Usuń" /></td>
				</tr>
</table>
		<%if (session.getAttribute("delete") != null) {
	%>
	<span><%= session.getAttribute("delete") %></span> 
	<%
		session.removeAttribute("delete");
		}
	%>


	</form>


</div>
<%} %>